/**
 * Created by songj on 2015/12/11.
 */
define(['angular',
    'framework/msg/GillionMsgModule',
    'framework/dataGrid/DataGridModule',
    'framework/pagination/GillionPaginationModule',
    'framework/datasource/DataSourceModule',
    'framework/dropdown/GillionDropdownModule',
    'framework/date/DateModule',
    'angular-underscore',
    'system2/RulePermissionModule',
    'system2/RuleStatusModule',
], function (angular) {
    var module = angular.module('ParamController',
        ['GillionMsgModule', 'DataGridModule', 'GillionPaginationModule',
            'DataSourceModule', 'DateModule','RulePermissionModule', 'GillionDropdownModule','RuleStatusModule'])
        .controller('ParamController', ['$scope', 'GillionMsgService', '$dataSourceManager', '$timeout', 'Arrays','$location','Resource',
                function ($scope, GillionMsgService, $dataSourceManager, $timeout, Arrays, $location,Resource) {
                    $scope.all = GillionMsgService.getInputData();
                    if($scope.all.unitCaseId){
                        $scope.unitCaseParam=$scope.all;
                    }else{
                        $scope.unitCaseParam=$scope.all.unitCaseParam;
                    }
                    //$scope.unitCaseParam=GillionMsgService.getInputData();
                    $scope.packageId=$scope.unitCaseParam.packageId;
                    var unitCaseParams = Resource("/grule-manager/unitcases/params/:id", {
                        id: "@id"
                    });

                    if($scope.unitCaseParam.dataType=='Object'){
                        $('#dataType').attr("disabled","disabled")
                    }

                    $scope.submit=function(){
                        var unitCaseParam = $scope.unitCaseParam;
                        if(unitCaseParam.dataType=='Object') {
                            $scope.unitCaseParam.param='Object';
                        }
                        $scope.ParamForm.verify().then(function() {
                            if (unitCaseParam.id) {
                                unitCaseParams.update(unitCaseParam, function (response) {
                                    GillionMsgService.close();
                                });
                            } else {
                                unitCaseParams.create(unitCaseParam, function (response) {
                                    GillionMsgService.close();
                                });
                            }
                        });
                    };

                    $scope.cancel = function(){
                        GillionMsgService.close();
                    }
                }
            ]
        );

    module.config(['$locationProvider', function($locationProvider) {
        $locationProvider.html5Mode(true);
    }]);
    return module;
});
